/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SalidaEntrada.java
 *
 * Created on 21/03/2012, 04:13:00 PM
 */
package co.edu.eam.clinica.vista.gui.inventario;

import co.edu.eam.clinica.vista.controladores.inventario.controladorDialogoInventario;
import co.edu.eam.clinica.vista.controladores.varios.controladorFuncionario;
import co.edu.eam.clinica.vista.gui.common.BotonOncologos;
import co.edu.eam.clinica.vista.gui.common.PanelOncologos;
import co.edu.eam.clinica.vista.gui.common.VentanaPrincipalManager;
import co.edu.eam.persitencia.entidades.Funcionario;
import co.edu.eam.persitencia.entidades.Inventario;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author diana
 */
public class PanelSalidaEntrada extends PanelOncologos {

    private controladorDialogoInventario dialogoInventario;
    private controladorFuncionario funcionario;
    private List<Inventario> inventarios;

    /**
     * Creates new form SalidaEntrada
     */
    public PanelSalidaEntrada() {
        initComponents();
        dialogoInventario = new controladorDialogoInventario();
        funcionario = new controladorFuncionario();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTxCodArticulo = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaInventario = new javax.swing.JTable();
        tfCodigoBarras = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jbcrear = new javax.swing.JButton();

        jLabel1.setText("Codigo Articulo:");

        tablaInventario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Codigo Articulo", "Codigo de Barras", "Nombre", "Fecha Entrada", "Fecha Salida", "Responsable entrada", "Responsable Salida"
            }
        ));
        jScrollPane1.setViewportView(tablaInventario);

        jLabel2.setText("Codigo de Barras");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/torresquintero/oncologos/medico/imagenes/imagenes/16x16/buscar-buscar-ampliar-icono-4271-32 - copia.png"))); // NOI18N
        jButton2.setText("Buscar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/torresquintero/oncologos/medico/imagenes/imagenes/24x24/editar-borrar-icono-5828-32.png"))); // NOI18N
        jButton3.setText("Eliminar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jbcrear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/torresquintero/oncologos/medico/imagenes/imagenes/24x24/editar-borrar-icono-5828-32.png"))); // NOI18N
        jbcrear.setText("guardar");
        jbcrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbcrearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 815, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tfCodigoBarras, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTxCodArticulo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
                        .addGap(56, 56, 56)
                        .addComponent(jButton2)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGap(20, 20, 20)
                    .addComponent(jbcrear)
                    .addGap(599, 599, 599)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTxCodArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfCodigoBarras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(125, 125, 125))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(218, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jbcrear, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addGap(76, 76, 76)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
}//GEN-LAST:event_bGuardarActionPerformed

    private void bSalidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSalidaActionPerformed
}//GEN-LAST:event_bSalidaActionPerformed

    private void bEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bEntradaActionPerformed
    }//GEN-LAST:event_bEntradaActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jbcrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbcrearActionPerformed

        try {

            String funci = JOptionPane.showInputDialog(null, "INGRESE DOCUMENTO DE QUIEN INGRESA EL INV");
            Funcionario fun = funcionario.buscarFuncionario(funci);
            if (fun != null) {
                Date fechaIngreso = new Date();
                String codigo = tfCodigoBarras.getText();

                try {
                    Inventario inv = new Inventario(fechaIngreso, codigo, fun);
                    dialogoInventario.crearInventario(inv);
                    inventarios.add(inv);

//                    DefaultTableModel modelo = (DefaultTableModel) tablaInventario.getModel();
//                    int id = tablaInventario.getSelectedRow();
//                    String cod = (String) tablaInventario.getValueAt(id, 0);
//
//                    DialogoInventario panel = new DialogoInventario(cod);
//                    VentanaPrincipalManager.agregarVentana(panel);
//
//                    this.tablaInventario.setModel(modelo);


                    JOptionPane.showMessageDialog(null, "listo inventario guardado");

                } catch (Exception ex) {
                    Logger.getLogger(PanelSalidaEntrada.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {

                JOptionPane.showMessageDialog(null, "este funcionario no existe");
            }

        } catch (Exception ex) {
            Logger.getLogger(PanelSalidaEntrada.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jbcrearActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        
        
    }//GEN-LAST:event_jButton2ActionPerformed

    public void llenarTabla() {
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTxCodArticulo;
    private javax.swing.JButton jbcrear;
    private javax.swing.JTable tablaInventario;
    private javax.swing.JTextField tfCodigoBarras;
    // End of variables declaration//GEN-END:variables
}
